package com.nanbei.list;

import org.junit.Test;

public class SinglyLinkedListTest {


    @Test
    public void test1(){
        SinglyLinkedList list = new SinglyLinkedList();

        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.addFirst(5);
        list.addFirst(6);

        list.loop();
        System.out.println("-----------------------------");
        list.loop2(System.out::println);
        System.out.println("-----------------------------");
        for (Integer value : list) {
            System.out.println(value);
        }

    }

    @Test
    public void test2(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.addFirst(5);
        list.addFirst(6);

        list.addLast(888);
        list.loop2(System.out::println);
        System.out.println("-----------------------------");
    }

    @Test
    public void test3(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.addLast(6);

        System.out.println(list.get(3));
        System.out.println("-----------------------------");

        list.insert(0,0);
        list.insert(2,222);
        list.insert(7,777);
        list.loop2(System.out::println);
        System.out.println("----------------------------");
        list.insert(9,999);
        list.loop2(System.out::println);
        list.insert(11,111);
    }

    @Test
    public void test4(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.addLast(6);

        list.del(4);
        list.loop2(System.out::println);
    }


    @Test
    public void test5(){
        DoublyLinkedListSentinel list = new DoublyLinkedListSentinel();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.addLast(6);

        list.insert(1,90);
        System.out.println("-------------");
        list.loop2(System.out::println);
    }


}
